package com.cxd.redis;







import org.apache.log4j.Logger;

import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;

public class RedisCacheManger implements  RedisCache {
	 private ShardedJedisPool pool ;  
     
	    private Logger log = Logger.getLogger(RedisCacheManger.class);
	    
	    public ShardedJedisPool getPool() {  
	        return pool;  
	    }  
	  
	    public void setPool(ShardedJedisPool pool) {  
	        this.pool = pool;  
	    }  
	  
	    @SuppressWarnings("deprecation")
		public <T> T getRedisCacheInfo(String key) {  
	          
	        try {  
	            log.info("get from redisCache :"+key);  
	            System.out.println("get from rediscache");  
	            ShardedJedis jedis = pool.getResource();  
	            pool.returnResource(jedis);  
	            return (T)jedis.get(key);  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	        return null;  
	    }  
	   
	  
	    @SuppressWarnings("deprecation")
		public <T> boolean setRedisCacheInfo(String key, T value) {  
	  
	        try {  
	            log.info("add to redisCache :"+key);  
	            System.out.println("add to rediscache");  
	            ShardedJedis jedis = pool.getResource();  
	            jedis.set(key, (String)value);  
	            pool.returnResource(jedis);  
	            return true;  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	        return false;  
	    }  
	    public static void main(String[] args) {  
	        new RedisCacheManger().setRedisCacheInfo("12345", "asdfg");  
	    }  
}
